package com.baosight.risk.service.zbaa.impl;

import com.baosight.risk.api.zbaa.IZbaaTargetGroupOrderService;
import com.baosight.risk.base.service.BaseServiceImpl;
import com.baosight.risk.common.bean.BeanUtils;
import com.baosight.risk.mapper.zbaa.ZbaaTargetGroupOrderMapper;
import com.baosight.risk.service.zbaa.entity.ZbaaTargetGroupOrder;
import com.baosight.risk.service.zbaa.vo.ZbaaTargetGroupVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class ZbaaTargetGroupOrderServiceImpl extends BaseServiceImpl<ZbaaTargetGroupOrder> implements IZbaaTargetGroupOrderService {

    @Autowired
    ZbaaTargetGroupOrderMapper zbaaTargetGroupOrderMapper;

    @Override
    public Integer deleteByGroupId(String groupId) {
        return zbaaTargetGroupOrderMapper.deleteByGroupID(groupId);
    }

    @Override
    public List<ZbaaTargetGroupOrder> selectGroupOrderByGroupId(String id) {
        List<ZbaaTargetGroupOrder> resultList = zbaaTargetGroupOrderMapper.selectGroupOrderByGroupId(id);
        return resultList;
    }

    @Override
    public void saveTargetGroupOrder(ZbaaTargetGroupVo targetGroupVo) {
        String groupId = targetGroupVo.getGroupId();
        // 先删除当前组全部订阅信息
        zbaaTargetGroupOrderMapper.deleteByGroupID(groupId);
        // 再添加当前组新信息
        for (ZbaaTargetGroupOrder zbaaTargetGroupOrder : targetGroupVo.getDataList()) {
            //初始化基本参数
            zbaaTargetGroupOrder = (ZbaaTargetGroupOrder) BeanUtils.initBean(zbaaTargetGroupOrder);
            zbaaTargetGroupOrderMapper.insert(zbaaTargetGroupOrder);
        }
    }
}
